package edu.lingnan.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import edu.lingnan.dto.LogListReq;
import edu.lingnan.entity.Log;
import edu.lingnan.service.LogService;
import edu.lingnan.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @ClassName LogController
 * @Description TODO
 * @Author kang
 * @Date 2022/9/14 下午 8:47
 * @Version 1.0
 */
@RestController
@Api(tags = "日志模块")
@RequestMapping("/log")
public class LogController {

    @Autowired
    private LogService logService;

    @PostMapping("list")
    @ApiOperation("获得日志列表（分页）")
    public Result list(@Valid @RequestBody @ApiParam("分页参数") LogListReq logListReq){
        Page<Log> page = logService.page(
                new Page<Log>(logListReq.getCurrentPage(), logListReq.getSize()),
                new LambdaQueryWrapper<Log>().orderByDesc(Log::getLogId).orderByDesc(Log::getLogId)
        );
        return new Result(true, page, "展示日志信息成功");
    }

}
